﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Configuration;
using System.Reflection;


namespace SAW_Core
{
    public class PDFCreator
    {

        public PDFCreator()
        {
        }

        public void CrearPDFdeHTML(string html, string nombreSalida, string rutaGuardado, bool landScape, bool Mostrar)
        {

            CrearPDFdeHTML(html, nombreSalida, rutaGuardado, landScape, 12, 12, 12, 12, 9, Mostrar,612 ,792);
        }

        

        public void CrearPDFdeHTML(string html, string nombreSalida, string rutaGuardado, bool landScape, int leftMargin, int topMargin, int rightMargin, int bottomMargin, int media, bool mostrar,int pageWidth, int pageHeight)
        {
            //string path1 = HttpContext.Current.Server.MapPath("/");
            //string TempName = rutaGuardado + nombreSalida+".pdf";
            //string directoryName = rutaGuardado;
            //System.IO.DirectoryInfo directorio = new System.IO.DirectoryInfo(path1 + directoryName);
            //if (!directorio.Exists)
            //    directorio.Create();
            //IPdfManager objPdf = new PdfManager();
            //IPdfDocument objDoc = objPdf.CreateDocument(Missing.Value);
            //string strparams = "PageWidth="+pageWidth+";PageHeight="+pageHeight+";Landscape=" + landScape + ";LeftMargin=" + leftMargin + ", RightMargin=" + rightMargin + ", TopMargin=" + topMargin + ", BottomMargin=" + bottomMargin + ";media=" + media + "";
            //objDoc.ImportFromUrl(html, strparams, Missing.Value, Missing.Value);
            //objDoc.Save(HttpContext.Current.Server.MapPath(TempName), true);
            ////HttpContext.Current.Response.Redirect( nombreSalida + ".pdf");
            //string path = HttpContext.Current.Server.MapPath(TempName);
            //System.IO.FileInfo file = new System.IO.FileInfo(path);
            //if (file.Exists && mostrar)
            //{
            //    HttpContext.Current.Response.Clear();
            //    HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + nombreSalida + ".pdf");
            //    HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());
            //    HttpContext.Current.Response.ContentType = "application/octet-stream";
            //    HttpContext.Current.Response.WriteFile(file.FullName);
            //    //file.Delete();
            //    HttpContext.Current.Response.End();
            //}
        }
    }
}
